<div class="layout_content graybg">
    <header class="demo-header" style="padding-top: 10px;">
        <div class="titleLeft flt">
            <a href="index.html">
                <img src="<?php echo WEBIMG; ?>/back.png" width="35px" height="33px">
            </a>
        </div>
        <div class="titleRight flt text-center">确认订单</div>
    </header>
    <div class="whitebg">
        <div class="sizecolor">配送信息</div>
        <div class="message-detail">
            <p class="padding-adjust2">
                收货人：
                <input class="input" id="cnee" type="text" placeholder="请输入收货人"
                       value="<?php echo $userInfo['contact']; ?>" maxlength="30" required>
                <a class="clear" onclick="javascript:document.getElementById('cnee').value=''"></a></p>
            <p>
                联系方式：
                <input class="input" id="cnee-tel" type="text" placeholder="请输入联系方式"
                       value="<?php echo $userInfo['tel']; ?>" maxlength="30" required>
                <a class="clear" onclick="javascript:document.getElementById('cnee-tel').value=''"></a></p>
            </p>
            <p>
                收货地址：
                <input class="input" id="cnee-addr" type="text" placeholder="请输入收货地址"
                       value="<?php echo $userInfo['provincename'] . '' . $userInfo['cityname'] . '' . $userInfo['areaname'] . '' . $userInfo['address']; ?>"
                       maxlength="30" required>
                <a class="clear" onclick="javascript:document.getElementById('cnee-addr').value=''"></a></p>
            </p>
            <p>
                备注信息：
                <input class="input" id="beizhu" type="text" placeholder="请输入备注信息（可选）" maxlength="30" required>
                <a class="clear" onclick="javascript:document.getElementById('beizhu').value=''"></a></p>
            </p>
        </div>
    </div>
    <div class="whitebg">
        <div class="sizecolor flt" style="width: 40%;padding-right: 0;padding-bottom: 5px;">配送时间</div>
        <div class="flt text-right" style="width: 53%;font-size: 0.75em;padding: 12px 0 0 0;" id="delivery_time"
             onclick="timeShow()">
            请选择
        </div>
    </div>
    <div class="whitebg">
        <div class="sizecolor flt">商品信息</div>
        <div class="frt sizecolor grayarrow" style="padding-top: 3px;">></div>
        <div class="clear_both"></div>
        <div class="ordetail-img">
            <?php foreach ($orderBody as $pro) { ?>
                <div class="order-img">
                    <div>
                        <img src="<?php echo $pro['img'] ?>"/>
                    </div>
                    <div class="order-img-font">
                        <p class="product"><?php echo $pro['product_name'] ?> x<?php echo $pro['amount'] ?></p>
                        <p class="guige"><?php echo $pro['mass_packing'] ?></p>
                    </div>
                </div>
            <?php } ?>
        </div>
    </div>
    <div class="whitebg">
        <div class="sizecolor">选择支付</div>
        <div id="pay-select" class="zonge message-detail border-two pay-select">
            <?php if (count($payTypeList) > 0) { ?>
                <?php foreach ($payTypeList as $k => $v) { ?>
                    <span>
                    <input type="radio" name="pay_method" class="disn"
                           value="<?php echo $v['type']; ?>" <?php if ($v['is_checked'] == 1)
                        echo ' checked'; ?>/>
                <label rel="<?php echo $v['type']; ?>" <?php if ($v['is_checked'] == 1)
                    echo ' class="pay-check"'; ?>></label><?php echo $v['name']; ?>&nbsp;&nbsp;
                    </span>
                <?php } ?>
            <?php } ?>
        </div>
        <?php if ($payTypeList) { ?>
            <?php foreach ($payTypeList as $k => $v) { ?>
                <?php if ($v['type'] == 1) { ?>
                    <?php foreach ($v['items'] as $key => $val) { ?>
                        <div class="message-detail shangxiapay online_pay">
                            <div class="zonge flt nowrap">
                                <img src="<?php echo $val['icon']; ?>"
                                     class="img-middle img-padding1"
                                     style="width: 3em;height: 3em;"/><?php echo $val['name']; ?>
                            </div>
                            <div class="frt sizecolor grayarrow" style="padding-top: 3px;">
                                <input type="radio" name="online_method"
                                       value="<?php echo $val['id']; ?>" <?php if (!$val['is_checked'])
                                    echo ' checked'; ?> style="display: none;">
                                <?php if (!$val['is_checked']) { ?>
                                    <img src="<?php echo WEBIMG; ?>/shopcart_chk_selected.png" width="18px"
                                         height="18px" class="img-bottom"/>
                                <?php } else { ?>
                                    <img src="<?php echo WEBIMG; ?>/shopcart_chk_normal.png" width="18px"
                                         height="18px" class="img-bottom"/>
                                <?php } ?>
                            </div>
                        </div>
                    <?php } ?>
                <?php } else { ?>
                    <?php foreach ($v['items'] as $key => $val) { ?>
                        <?php if ($val['is_checked']) { ?>
                            <div class="clear_both"></div>
                            <div class="message-detail disn shangxiapay overline_pay" onclick="ShowAccount()">
                                <input type="radio" name="bank_method" id="bank_method"
                                       value="<?php echo $val['id']; ?>" checked style="display: none;">
                                <div class="zonge flt">收款账号</div>
                                <div class="frt sizecolor grayarrow" style="padding-top: 3px;">
                                    >
                                </div>
                                <div class="clear_both"></div>
                                <p>开户名称：<span id="bank_account"><?php echo $val['account']; ?></span></p>
                                <p>开户银行：<span id="bank_name"><?php echo $val['bank_name']; ?></span></p>
                                <p>开户账号：<span id="bank_number"><?php echo $val['bank_number']; ?></span></p>
                            </div>
                        <?php } ?>
                    <?php } ?>
                <?php } ?>
            <?php } ?>
        <?php } ?>
    </div>
    <div class="whitebg">
        <div class="zonge flt">结算总额</div>
        <div class="frt zonge" style=""><strong>￥<?php echo $orderHeader['price']; ?></strong></div>
        <div class="clear_both"></div>
        <div class="border-two text-right fontsize zhemanjian">
            <p>折扣：￥<?php echo $orderHeader['discount']; ?></p>
            <p>运费：￥0.00</p>
            <p>优惠：￥<?php echo $orderHeader['coupon']; ?></p>
        </div>
        <div class="flt padding-adjust4"><strong>合计</strong></div>
        <div class="frt money-color padding-adjust4" style="margin-bottom:3em; ">
            <strong>￥<?php echo $orderHeader['price']; ?></strong></div>
        <div class="clear_both"></div>
        <div class="dibu-fixed" style="padding-left: 0;">
            <div class="flt confirm-dibu1 padding-adjust2">需付款：<strong>￥<?php echo $orderHeader['price']; ?></strong>
            </div>
            <div class="flt confirm-dibu2" onclick="saveOrder()">提交订单</div>
        </div>
    </div>
</div>

<!--选择时间-->
<div id="fade" class="black_overlay" style="height: 123%;"></div>
<div id="guige" class="timeguige text-center" style="width: 90%;left: 5%;bottom: 70px;">
    <div class="fontsize padding-adjust4 graybg" style="border-top-left-radius: 8px;border-top-right-radius: 8px;">
        <strong>请选择配送时间</strong></div>
    <div id="sese" style="height:275px ;overflow: auto;">
        <?php if ($dataList && count($dataList) > 0) { ?>
            <?php foreach ($dataList as $key => $val) { ?>
                <div class="time" value=""><?php echo $val; ?></div>
                <div class="pay-select" style="text-align: left;">
                    <input name="delivery_time" class="disn" type="radio" value="<?php echo $val; ?>">
                    <label></label>
                </div>
                <div class="clear_both"></div>
            <?php } ?>
        <?php } ?>
    </div>
    <div class="time-cofirm" onclick="CloseTime();">确认</div>
</div>

<!--选择线下支付方式-->
<div id="account" style="height: 260px;overflow: auto;">
    <?php foreach ($payTypeList as $k => $v) { ?>
        <?php if ($v['type'] == 0) { ?>
            <?php foreach ($v['items'] as $key => $val) { ?>
                <div class="message-detail">
                    <div class="flt" style="width: 85%;">
                        <p>开户名称：<?php echo $val['account']; ?></p>
                        <p>开户银行：<?php echo $val['bank_name']; ?></p>
                        <p>开户账号：<?php echo $val['bank_number']; ?></p>
                    </div>
                    <div class="zonge pay-select flt text-center" style="width: 15%;">
                        <input type="radio" name="tmp_overline_pay" class="disn" value="<?php echo $val['id']; ?>"
                               style="display: none;"/>
                        <label<?php if ($val['is_checked'])
                            echo ' class="pay-check"'; ?> onclick="selectAccount(this)"
                                                          data-id="<?php echo $val['id']; ?>"
                                                          data-account="<?php echo $val['account']; ?>"
                                                          data-name="<?php echo $val['bank_name']; ?>"
                                                          data-number="<?php echo $val['bank_number']; ?>"></label>
                    </div>
                </div>
                <div class="clear_both"></div>
            <?php } ?>
        <?php } ?>
    <?php } ?>
</div>
<div id="fadeAccount" class="black_overlay" style="height: 123%;" onclick="CloseAccount();"></div>

<script type="text/javascript">
    $(function () {
        $("#pay-select label").bind('click', function () {
            var type = $(this).attr('rel');
            if (type == 1) {
                $(".online_pay").show();
                $(".overline_pay").hide();
            } else {
                $(".online_pay").hide();
                $(".overline_pay").show();
            }
            if ($(this).hasClass('pay-check')) {
                return false;
            } else {
                $(this).addClass('pay-check');
                $(this).siblings('input').prop('checked', true);
                $(this).parent().siblings().find('input').prop('checked', false);
                $(this).parent().siblings().find('label').removeClass('pay-check');
            }
        });

        $("#sese .pay-select").bind('click', function () {
            $(this).find('input').prop('checked', true);
            $(this).find('label').addClass('pay-check');
            $(this).siblings('.pay-select').find('input').prop('checked', false);
            $(this).siblings('.pay-select').find('label').removeClass('pay-check');
        });
    });
    function timeShow() {
        $("#fade").fadeIn("slow");
        $("#guige").slideDown();
    }
    function CloseTime() {
        $("#fade").fadeOut("slow");
        $("#guige").slideUp();
        var send_time = $("#guige").find('.pay-check').siblings('input').val();
        $("#delivery_time").html(send_time);
    }
    function ShowAccount() {
        $("#fadeAccount").fadeIn("slow");
        $("#account").slideDown();
        document.body.style.overflow = 'hidden';
    }
    function CloseAccount() {
        $("#account").slideUp();
        $("#fadeAccount").fadeOut("slow");
        document.body.style.overflow = '';
    }
    function selectAccount(el) {
        var id = $(el).attr('data-id');
        var name = $(el).attr('data-name');
        var account = $(el).attr('data-account');
        var number = $(el).attr('data-number');

        $("#bank_name").html(name);
        $("#bank_account").html(account);
        $("#bank_number").html(number);
        $("#bank_method").val(id);
        CloseAccount();
    }
    function saveOrder() {
        var cnee = $("#cnee").val();
        var cnee_tel = $("#cnee-tel").val();
        var cnee_addr = $("#cnee-addr").val();
        var key = '<?php echo $cart;?>';
        var order_id = '<?php echo $orderHeader['id'];?>';
        var pay_method = $('input[name="pay_method"]:checked').val();
        var bank_method = $('input[name="bank_method"]:checked').val();
        var online_method = $('input[name="online_method"]:checked').val();
        var memo = $("#beizhu").val();
        var delivery_time = $("input[name='delivery_time']:checked").val();
        if (!cnee || !cnee_tel) {
            Tip('请输入收货人和联系方式');
            return false;
        }
        $.ajax({
            url: '/ajax/order/',
            type: 'post',
            dataType: 'json',
            data: {
                'ajaxdata': 'saveOrder',
                'key': key,
                'order_id': order_id,
                'ship_name': cnee,
                'ship_tel': cnee_tel,
                'ship_address': cnee_addr,
                'pay_method': pay_method,
                'bank_method': bank_method,
                'online_method': online_method,
                'delivery_time': delivery_time,
                'memo': memo
            },
            success: function (response) {
                layer.closeAll();
                layer.msg(response.message);
                if (response.code == 200) {
                    setTimeout('window.location.href = "<?php echo WEBROOT . '/order/success/?id='.$orderHeader['id'];?>"', 800);
                }
            },
            beforeSend: function () {
                layer.load(1);
            }
        });
    }
</script>
